package com.nuoniu.sibanyun.controller.erp.in;


import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.exception.NuoNiuException;
import com.nuoniu.sibanyun.common.lang.StringUtils;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.erp.in.InInventory;
import com.nuoniu.sibanyun.entity.erp.in.InInventoryClass;
import com.nuoniu.sibanyun.service.erp.in.IInInventoryClassService;
import com.nuoniu.sibanyun.service.erp.in.IInInventoryService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 物料分类 前端控制器
 * </p>
 *
 * @author baiqiang
 * @since 2020-09-22
 */
@RestController
@RequestMapping("/in/inventoryClass")
@Api(value = "物料分类", tags = "物料分类")
public class InInventoryClassController extends BaseController {

    @Autowired
    private IInInventoryClassService inventoryClassService;

    /**
     * 获取物料分类
     * @author 小啊刚
     * @date 2020-09-23
     */
    @GetMapping("getInventoryClassList")
    @ApiOperation(value = "获取物料分类列表")
    public HttpResult<InInventoryClass> getInventoryClassList() {
        return HttpResult.ok(inventoryClassService.getInventoryClassList());
    }

    /**
     * 保存物料分类
     * @author 小啊刚
     * @date 2020-09-23
     */
    @PostMapping("save")
    @ApiOperation(value = "保存物料分类")
    public HttpResult save(@RequestBody InInventoryClass inInventoryClass) {
        if(StringUtils.isBlank(inInventoryClass.getClassName())) {
            throw new NuoNiuException("物料分类名称不能为空");
        }

        if(StringUtils.isBlank(inInventoryClass.getClassCode())) {
            throw new NuoNiuException("物料分类编码不能为空");
        }

        inventoryClassService.saveInventoryClass(inInventoryClass);
        return HttpResult.ok();
    }

    /**
     * 删除物料分类
     * @author 小啊刚
     * @date 2020-09-23
     */
    @GetMapping("delete")
    @ApiOperation(value = "删除物料分类")
    public HttpResult delete(@ApiParam(name="id",value="物料分类id",required=true)Integer id, @ApiParam(name="parentId",value="上级id")Long parentId) {
        if(id == null) {
            throw new NuoNiuException("id不能为空");
        }

        inventoryClassService.deleteById(id, parentId);
        return HttpResult.ok();
    }


}
